//
//  FHStatusToolsBar.swift
//  WeiBo
//
//  Created by qfh on 16/7/13.
//  Copyright © 2016年 qiufuhe. All rights reserved.
//

import UIKit



class FHStatusToolsBar: UIView {

    
    var statusView: FHStatusViewModel? {
    
        didSet {
    
            self.retweetButton.setTitle(statusView?.retweetStr, forState: .Normal)
            
            self.commentButton.setTitle(statusView?.commentStr, forState: .Normal)
            
            self.unlikeButton.setTitle(statusView?.unlikeStr, forState: .Normal)
        
            
        
        }
    }
    
 
    private lazy var retweetButton: UIButton = self.addChildButton("timeline_icon_retweet", title: "转发")
    
    private lazy var commentButton: UIButton = self.addChildButton("timeline_icon_comment", title: "转发")
    
    private lazy var unlikeButton: UIButton = self.addChildButton("timeline_icon_unlike", title: "转发")
    
    
    override init(frame: CGRect) {
        super.init(frame: frame)
        
        setUpUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }

    func setUpUI() {
    
        addSubview(retweetButton)
        
        addSubview(commentButton)
        
        addSubview(unlikeButton)
        
        
        retweetButton.snp_makeConstraints { (make) -> Void in
            
            make.leading.equalTo(self)
            
            make.top.equalTo(self)
            
            make.bottom.equalTo(self)
            
            make.width.equalTo(commentButton)
            
        }
        
        commentButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(retweetButton.snp_trailing)
            
            make.top.equalTo(self)
            
            make.bottom.equalTo(self)
            
            make.width.equalTo(unlikeButton)
            
            
        }
        unlikeButton.snp_makeConstraints { (make) -> Void in
            make.leading.equalTo(commentButton.snp_trailing)
            
            make.top.equalTo(self)
            
            make.bottom.equalTo(self)
            
            make.trailing.equalTo(self)
            
        }
        

    
    
    }
    
    private func addChildButton(imageName: String, title: String) -> UIButton {
    
        
        let button: UIButton = UIButton()
        
        
        button.setImage(UIImage(named: imageName), forState: .Normal)
        
        button.setBackgroundImage(UIImage(named: "timeline_card_bottom_background"), forState: .Normal)
        
        button.adjustsImageWhenHighlighted = false
        
        
        button.setTitle(title, forState: .Normal)
        
        button.titleLabel?.font = UIFont.systemFontOfSize(15)
        
        button.setTitleColor(UIColor.grayColor(), forState: .Normal)
        
        
        
        return button
        
    }
    
    
    

}
